package com.huanong.controller.impl;
/*
 *@Author:anran
 *@Date:2020/12/7
 *@Version 1.0
 */

import com.huanong.common.grace.result.GraceJSONResult;
import com.huanong.controller.NewsControllerApi;
import com.huanong.pojo.NewWork;
import com.huanong.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class NewsController implements NewsControllerApi {

    @Autowired
    private NewsService newsService;

    @Override
    public GraceJSONResult query() {
        List<NewWork> list=newsService.query();
        return GraceJSONResult.ok(list);
    }

    @Override
    public GraceJSONResult queryById(Integer NkId) {
        NewWork newWork=newsService.queryById(NkId);
        return GraceJSONResult.ok(newWork);
    }

    @Override
    public GraceJSONResult addNews(NewWork newWork) {
        int flag=newsService.add(newWork);
        if (flag==1){
            return GraceJSONResult.ok("添加新闻信息成功");
        }else {
            return GraceJSONResult.errorMsg("添加新闻信息失败");
        }
    }

    @Override
    public GraceJSONResult delete(Integer NkId) {
        int flag=newsService.delete(NkId);
        if (flag!=0){
            return GraceJSONResult.ok("删除新闻信息成功");
        }else {
            return GraceJSONResult.errorMsg("删除新闻信息失败");
        }
    }

    @Override
    public GraceJSONResult updateNews(NewWork newWork) {
        int flag=newsService.update(newWork);
        if (flag!=0){
            return GraceJSONResult.ok("更新新闻信息成功");
        }else {
            return GraceJSONResult.errorMsg("更新新闻信息失败");
        }
    }
}
